#include <iostream>
using namespace std;
struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode(int x)
	: val(x)
	, left(nullptr)
	, right(nullptr)
    {
    }
};

struct tempres{
	bool balance;
	int high;
};

tempres pro(TreeNode* root)
{
	if(root == nullptr){
		return {true,0};
	}
	tempres res;
	tempres temp1= pro(root->left);
	tempres temp2= pro(root->right);
	res.high = max(temp1.high,temp2.high)+1;
	if(temp1.balance == false || temp2.balance == false || abs(temp1.high-temp2.high) > 1){
		res.balance=false;
	}else{
		res.balance=true;
	}
	return res;
}

bool isBalanced(TreeNode* root)
{
	return pro(root).balance;
}

int main(int argc, char* argv[])
{

    return 0;
}
